#include <iostream>

#include "ExampleClass.h"
#include "ExampleClassTest.h"
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TextTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>

int main() {
	/// initialize functionNames
	Demo::ExampleClassTest();

	CppUnit::TestResult controller;
	CppUnit::TestResultCollector result;
	controller.addListener(&result);
	CppUnit::TextTestProgressListener dotMaker;
	controller.addListener(&dotMaker);

	CppUnit::TestRunner testRunner;
	testRunner.addTest(Demo::ExampleClassTest::suite());
	while(!Demo::ExampleClassTest::functionNames.empty()) {
		std::string currentFunction = Demo::ExampleClassTest::functionNames.back();
		Demo::ExampleClassTest::functionNames.pop_back();
		try {
			std::cout << "Testing function:" << currentFunction << "... ";
			testRunner.run(controller, currentFunction);
			std::cout << std::endl;
		} catch (std::invalid_argument &ex) {
			std::cout << ex.what() << std::endl;
			continue;
		}
	}
	CppUnit::CompilerOutputter outputter(&result,std::cout);
	outputter.write();
	std::cout << std::endl << (result.wasSuccessful() ? "[All tests passed]" : "[There were errors]") << std::endl;
	system("PAUSE");
	return 0;
}